package com.orgname.glvone.glvtwo.web.controller;

import com.orgname.glvone.glvtwo.common.response.Response;
import com.orgname.glvone.glvtwo.service.UserService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiParam;
import io.swagger.v3.oas.annotations.Operation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.validation.constraints.NotEmpty;

@Api(tags = "登录接口")
@Slf4j
@RestController
@RequestMapping("/")
@Validated
public class LoginController {

    @Resource
    UserService userService;

    @Operation(summary = "登录")
    @GetMapping("login")
    public Response login(
            @ApiParam(required = true, value = "用户名")
            @NotEmpty(message = "用户名不能为空") String name,
            @ApiParam(required = true, value = "密码")
            @NotEmpty(message = "密码不能为空") String password) {
        return Response.succeededResponse(userService.login(name, password));
    }

    @Operation(summary = "login/other")
    @GetMapping("login/other")
    public Response login(String name) {
        return Response.succeededResponse(userService.loginOther(name));
    }

    @Operation(summary = "validateTicket")
    @GetMapping("validateTicket")
    public Response validateTicket(
            @ApiParam(required = true, value = "用户名")
            @NotEmpty(message = "参数不能为空") String ticket) {
        return Response.succeededResponse(userService.validateTicket(ticket));
    }

}
